package cn.maszy.action.systemsetting;

import java.io.UnsupportedEncodingException;

import net.sourceforge.stripes.action.SessionScope;

import org.springframework.beans.factory.annotation.Autowired;

import cn.maszy.common.BaseAction;
import cn.maszy.common.DateTools;
import cn.maszy.common.DateUtils;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.model.systemsetting.B_T_Sys_OperatingLogs;
import cn.maszy.service.systemsetting.B_T_Sys_OperatingLogsService;
@SessionScope
public class MyWorkLogAction extends BaseAction<B_T_Sys_OperatingLogs>{

	/**
	 * 版本信息
	 */
	private static final long serialVersionUID = 1L;
	private B_T_Sys_OperatingLogs b_T_Sys_OperatingLogs;
	@Autowired
	private  B_T_Sys_OperatingLogsService b_T_Sys_OperatingLogsService;
	private String checkIds;
	//报工日期开始
	private String strattime;
	//报工日期结束
	private String endtime;
	//逻辑判断
	private String flag;
	private String tab;
	//任务ID
	private String taskid;
	/*********************class set/get****************************/
	public B_T_Sys_OperatingLogs getB_T_Sys_OperatingLogs() {
		return b_T_Sys_OperatingLogs;
	}
	public void setB_T_Sys_OperatingLogs(B_T_Sys_OperatingLogs b_T_Sys_OperatingLogs) {
		this.b_T_Sys_OperatingLogs = b_T_Sys_OperatingLogs;
	}
	public String getCheckIds() {
		return checkIds;
	}
	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public String getStrattime() {
		return strattime;
	}
	public void setStrattime(String strattime) {
		this.strattime = strattime;
	}
	public String getEndtime() {
		return endtime;
	}
	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public String getTaskid() {
		return taskid;
	}
	public void setTaskid(String taskid) {
		this.taskid = taskid;
	}
	public String getTab() {
		return tab;
	}
	public void setTab(String tab) {
		this.tab = tab;
	}
	/*******************STRUTS ACTION METHOD*************************/
	/**
	 * 插入
	 */
	public String workLogUpdate()
	{
		int i=b_T_Sys_OperatingLogsService.update(b_T_Sys_OperatingLogs);
		if(i >0 )
		return ajaxForwardSuccess(getText("msg.operation.success"), "MyWorkLogList","", "forward", "systemsetting/MyWorkLogList?flag=2&strattime="+DateUtils.now()+"&endtime="+DateUtils.now()+"&b_T_Sys_OperatingLogs.operatingName="+SessionFactory.getSessionUserRealNam());
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 查询
	 * @return
	 */

	public  String workLogList() 
	{
		pager = new Pager<B_T_Sys_OperatingLogs>(pageNum, numPerPage,orderField,orderDirection);
		if(b_T_Sys_OperatingLogs != null && "2".equals(flag)){
			if(!"1".equals(tab) || "".equals(tab)){
				if(b_T_Sys_OperatingLogs.getOperatingName()!=null && !"".equals(b_T_Sys_OperatingLogs.getOperatingName())){
					try {
							b_T_Sys_OperatingLogs.setOperatingName(new String(b_T_Sys_OperatingLogs.getOperatingName().getBytes("ISO8859_1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
		if("create_time".equals(pager.getOrderField())){
			pager.setOrderField("operating_time");
			pager.setOrderDirection("ASC");
		}
		pager= b_T_Sys_OperatingLogsService.selectList(b_T_Sys_OperatingLogs,pager,strattime,endtime,flag,taskid);
		return SUCCESS;
	}
	/**
	 * 删除
	 * @return
	 */
	public String workLogDel()
	{
		int i=b_T_Sys_OperatingLogsService.delete(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "TaskManageList","", "forward", "projectmanagement/TaskManageList");
		return ajaxForwardError(getText("msg.operation.failure"));
	
	}

	//跳转到新建页面
	public String workLogDital() throws Exception
	{
		if(b_T_Sys_OperatingLogs==null){
			b_T_Sys_OperatingLogs=b_T_Sys_OperatingLogsService.selectOne("");
			b_T_Sys_OperatingLogs.setOperatingName(SessionFactory.getSessionUserRealNam());
			b_T_Sys_OperatingLogs.setOperatingTime(DateUtils.nows());
		}else{
			b_T_Sys_OperatingLogs=b_T_Sys_OperatingLogsService.selectOne(b_T_Sys_OperatingLogs.getLogsId());
		}
		return SUCCESS;
		
	}
}
